package com.dhh.nutrition.model;

import java.math.BigDecimal;
import com.dhh.nutrition.vo.Food;

public class NutritionFacts {
	private Food food;
	private int weightType = 0;
	private int weight = 100;
	

	public int getWeightType() {
		return weightType;
	}

	public void setWeightType(int weightType) {
		this.weightType = weightType;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
	
	public void setWeightType(int weight,int weightType){
		this.weightType = weightType;
		this.weight = weight;
		food.setType(weightType);
		food.setServing(weight);
	};
	
	public NutritionFacts(Food food){
		this.food = food;
	}	
	
	public String getServingSize(){
		if(this.weightType==0){
			return "1";
		}else if(this.weightType==1){
			return food.getGmWt_Desc1();			
		}else if(this.weightType==2){
			return food.getGmWt_Desc2();
		}
		
		return "1";
	}
	
	public String getServingWeight(){
		if(this.weightType==0){
			return "100";
		}else if(this.weightType==1){
			return formatNumber(food.getGmWt_1());			
		}else if(this.weightType==2){			
			return formatNumber(food.getGmWt_2());	
		}
		
		return "100";
	}
	
	public String getCalories(){
		return formatNumber(Double.valueOf(food.getEnerg_Kcal()).intValue());
	}
	
	public String getCaloriesFromFat(){
		return formatNumber(Double.valueOf(food.getLipid_Tot()).intValue()*9);
	}
	
	public String getTotalFat(){
		return formatNumber(food.getLipid_Tot());
	}
	
	public String getTotalFatDV(){
		return Double.valueOf(food.getLipid_Tot() / 65  * 100).intValue() +"%";
	}
	
	public String getSaturatedFat(){
		return formatNumber(food.getFA_Sat());
	}
	
	public String getSaturatedFatDV(){
		return Double.valueOf(food.getFA_Sat() / 20  * 100).intValue() +"%";
	}
	
	public String getTransFat(){
		return formatNumber((food.getFA_Poly()+food.getFA_Mono()));
	}
	
	public String getCholesterol(){
		return formatNumber(food.getCholestrl());
	}
	
	public String getCholesterolDV(){
		return Double.valueOf(food.getCholestrl() / 300  * 100).intValue() +"%";
	}
	
	public String getSodium(){
		return formatNumber(food.getSodium());
	}
	
	public String getSodiumDV(){
		return Double.valueOf(food.getSodium() / 2400  * 100).intValue() +"%";
	}
	
	public String getTotalCarbohydrate(){
		return formatNumber(food.getCarbohydrt());
	}
	
	public String getTotalCarbohydrateDV(){
		return Double.valueOf(food.getCarbohydrt() / 300  * 100).intValue() +"%";
	}
	
	public String getDietaryFiber(){
		return formatNumber(food.getFiber_TD());
	}
	
	public String getDietaryFiberDV(){
		return Double.valueOf(food.getFiber_TD() / 25  * 100).intValue() +"%";
	}
	
	public String getSugars(){
		return formatNumber(food.getSugar_Tot());
	}
	
	public String getProteins(){
		return formatNumber(food.getProtein());
	}
	
	public String getVitamADV(){
		return Double.valueOf(food.getVit_A_IU() / 5000 * 100).intValue() +"%";
	}
	
	public String getVitamCDV(){
		return Double.valueOf(food.getVit_C() / 60 * 100).intValue() +"%";
	}
	
	public String getCalclumDV(){
		return Double.valueOf(food.getCalcium() / 1000 * 100).intValue() +"%";
	}
	
	public String getIronDV(){
		return Double.valueOf(food.getIron() / 18 * 100).intValue() +"%";
	}	
	
	private String formatNumber(double value){
		BigDecimal b = new BigDecimal(value);
		double f1 = b.setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
		int fi = Double.valueOf(f1).intValue();
		if(f1-fi == 0){
			return String.valueOf(fi);
		}else{
			return String.valueOf(f1);
		}
	}
	
	public Food getFood(){
		return food;
	}
}
